home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / winsock / ircii2-6.zip / SCRIPTS\COMPLETE < prev    next >
Text File  |  1994-12-28  |  8KB  |  212 lines

  1. # Complete - by Ian Frechette (Daemon)
  2. # inspired by the tcsh shell 'complete' command
  3. # version .8 (alpha) Do NOT distribute
  4. # Tue Jul 13 13:16:01 MDT 1993
  5. @ RCS.complete = [$$Header: /splode/u/mrg/src/ircii-2.5/script/RCS/complete,v 1.1 1994/07/30 18:07:23 mrg Stab $$]
  6. #
  7. # Commands:
  8. #   compl.add [-null] [-nomatch] <command pattern> <command parser name>
  9. #  or
  10. #   compl.add <[-nulll] [-nomatch]> <command parser name>
  11. #  to add patterns and assciated parsers or just parsers to null and nomatch
  12. #  condition.  (See notes below for me info)
  13. #
  14. #   compl.list      Just list everything out..
  15.  
  16. # don't clobber existing lists when reloading complete
  17. if (!compl.list) {@ compl.list = []}
  18. if (!compl.parse) {@ compl.parse = []}
  19. if (!compl.null) {@ compl.null = []}
  20. if (!compl.null) {@ compl.nomatch = []}
  21.  
  22. # Bind TAB to call compl.parse with the contents of the input line
  23. bind ^I parse_command compl.parse $L
  24.  
  25. # alias compl.add 
  26. # Usage: compl.add [-null] [-nomatch] <command pattern> <command parser>
  27. # Usage: compl.add <[-null] [-nomatch]> <command parser>
  28. # e.g.  compl.add /msg message_parser      will call the message_parser 
  29. #                                         when TAB is pressed and /msg
  30. #                                         is the current command on the
  31. #                                         input line
  32. # -null specifies that the given <command parser> should be used when
  33. #       TAB is pressed and the input line is blank
  34. # -nomatch  specifies that the given <command parser> should be used
  35. #       when the current command at the head of the input line is not
  36. #       found in the list of <command pattern>s
  37. # can use just compl.add -null message_parser
  38. # or           compl.add -null -nomatch message_parser
  39. #      
  40. alias compl.add {
  41.     if ([$1])
  42.     {
  43.         @ compl.add.last = [$*]
  44.         @ compl.add.last = #compl.add.last
  45.         @ compl.tmp = 0
  46.         @ compl.flag.null = 0
  47.         @ compl.flag.nm = 0
  48.         if (compl.flag.null = rmatch(-null $*)) {@ compl.tmp = compl.tmp +1}
  49.         if (compl.flag.nm = rmatch(-nomatch $*)) {@ compl.tmp = compl.tmp +1 }
  50.  
  51.         # Need to make sure there is at least one morpe argument beyond
  52.         # the -null or -nomatch which we'll take as the parser name
  53.         if (compl.add.last > compl.tmp)
  54.         {
  55.             if (compl.flag.null) 
  56.             {
  57.                 if (compl.null) {echo *** compl.add: null call replaced.}
  58.                 @ compl.null = [$(${compl.add.last -1 })] 
  59.                 echo *** compl.add: null calls $compl.null
  60.             }
  61.             if (compl.flag.nm) 
  62.             {
  63.                 if (compl.nomatch) {echo *** compl.add: nomatch call replaced.}
  64.                 @ compl.nomatch = [$(${compl.add.last -1})]
  65.                 echo *** compl.add: nomatch calls $compl.nomatch
  66.             }
  67.             # Need both the pattern and parser for this part.
  68.             if ((compl.add.last - 2) == compl.tmp)
  69.             {
  70.                 # At this point compl.tmp should be 0 1 or 2
  71.                 # basically 1 past the last -null or -nomatch found
  72.                 push compl.list $($compl.tmp)
  73.                 push compl.parse $(${compl.tmp+1})
  74.                 echo *** compl.add: $($compl.tmp) $(${compl.tmp +1}) added
  75.             }
  76.         }
  77.         {   echo *** compl.add: Not enough arguments to do anything (1)}
  78.     }
  79.     {   echo *** compl.add: Not enough arguments to do anything (2)}
  80.     ^assign -compl.tmp
  81.     ^assign -compl.flag.null
  82.     ^assign -compl.flag.nm
  83. }
  84.  
  85. # alias compl.list   No arguments.
  86. # just list the various completion lists.
  87. alias compl.list {
  88.     # if there are items in the list
  89.     @compl.list.cnt = 0
  90.     @compl.list.flag = 0
  91.     echo *** $format(4 num): $lformat(17 Command Pattern) $lformat(15 Action taken)
  92.     if (compl.list)
  93.     {
  94.         @ compl.list.flag = 1
  95.         @ compl.tmp = #compl.list
  96.         while (compl.list.cnt < compl.tmp)
  97.         {
  98.             echo *** $format(4 ${compl.list.cnt +1}): $lformat(17 $word($compl.list.cnt $compl.list)) $lformat(15 $word($compl.list.cnt $compl.parse))
  99.             @ compl.list.cnt = compl.list.cnt + 1
  100.         }
  101.     }
  102.     if (compl.null)
  103.     {
  104.         @compl.list.cnt = compl.list.cnt + 1
  105.         @compl.list.flag = 1
  106.         echo *** $format(4 $compl.list.cnt): $lformat(17 <NULL PATTERN>) $lformat(15 $compl.null)
  107.     }
  108.     if (compl.nomatch)
  109.     {
  110.         @compl.list.cnt = compl.list.cnt + 1
  111.         @compl.list.flag = 1
  112.         echo *** $format(4 $compl.list.cnt): $lformat(17 <NO MATCH>) $lformat(15 $compl.nomatch)
  113.     }
  114.     if (!compl.list.flag) { echo *** compl.list: no completions set }
  115.  
  116.     ^assign -compl.tmp
  117.     ^assign -compl.list.flag
  118.     ^assign -compl.list.cnt
  119. }
  120.  
  121.  
  122. # alias compl.del   Delete an entry from the list of completions
  123. # Do a 'compl.list' first to get a list with numbers.
  124. # then issue a compl.del <item number> and walla.. gone poof.
  125. alias compl.del {
  126.     if (index(0123456789 $0) > -1)
  127.     {
  128.         @ c.d.len = #compl.list
  129.         if (([$0] > 0) && ([$0] <= c.d.len))
  130.         {
  131.             # notword() does boundary checking
  132.             @ compl.list = notword($0 $compl.list)
  133.             @ compl.parse = notword($0 $compl.parse)
  134.             if (#comp.list == c.d.len)
  135.                 { echo *** compl.del: Failed to remove item $0 from compl.list}
  136.                 { echo *** compl.del: removed item $0 from list of completions}
  137.         }
  138.         {if ([$0] == (c.d.len + 1))
  139.         {
  140.             if (compl.null)
  141.             {
  142.                 echo *** compl.del: Removed default null action
  143.                 @ compl.null = []
  144.             }
  145.             {
  146.                 echo *** compl.del: Removed default nomatch action
  147.                 @ compl.nomatch = []
  148.             }
  149.         }
  150.         {if (([$0] == (c.d.len + 2)) && (compl.null != []) && (compl.nomatch != []))
  151.         {
  152.             echo *** compl.del: Removed default nomatch action
  153.             @ compl.nomatch = []
  154.         }
  155.         {
  156.             echo *** compl.del: Selection not in range.  /coml.list for list
  157.         }}}
  158.     }
  159.     {
  160.         echo *** compl.del: Not a valid number. /compl.del <number to delete>
  161.         echo *** compl.del: /compl.list for a list of current completions
  162.     }
  163.     ^assign -c.d.len
  164. }
  165.             
  166.  
  167.  
  168. # alias compl.parse
  169. # This is the real guts of the whole script.  Don't let all the other
  170. # fool you. This is what is called when you press TAB.
  171. # It simply tries to find a match for the command word
  172. # ($0 of the input line) and if it finds one it calls the corresponding
  173. # parser with the entire input line as an argument.
  174. # There are two additional states
  175. # null == the command in the compl.null var is called when the input line
  176. #         is empty and compl.parse is called
  177. # nomatch == the command in the compl.nomatch var is called when the input
  178. #         line command word ($0) is not found in the list of commands
  179. #         compl.list
  180. alias compl.parse {
  181.     if ([$0])
  182.     {
  183.         if (compl.ptr = rmatch($0 $compl.list))
  184.         {
  185.             $word(${compl.ptr -1} $compl.parse) $*
  186.         }
  187.         {
  188.             if (compl.nomatch) {$compl.nomatch $*}
  189.         }
  190.     }
  191.     {
  192.         $compl.null
  193.     }
  194.     ^assign -compl.ptr
  195. }
  196.  
  197. # push an item onto the head of a list
  198. # this only takes the name of the list instead of the variable itself. 
  199. # examples.
  200. # /push list Item
  201. # or     if (push(list Item)) { echo push sucessful } { echo push failed }
  202. # echo $list returns 'Item'
  203. alias push {
  204.     if (![$1])
  205.     { @function_return = 0 }
  206.     { eval @ $0 = [$1- $($0)];@function_return = 1}
  207. }
  208.  
  209. alias debug if (ddebug) {echo *D* $*}
  210.  
  211.